home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group96a.txt / 000022_icon-group-sender _Mon Jan 22 16:04:35 1996.msg < prev    next >
Internet Message Format  |  1996-09-05  |  3KB

  1. Received: by cheltenham.cs.arizona.edu; Mon, 22 Jan 1996 16:25:25 MST
  2. From: Nick Williams <nmw@styx.ios.com>
  3. Message-Id: <199601222104.QAA03988@styx.ios.com>
  4. Subject: Hacking icon src; adding features
  5. To: icon-group@cs.arizona.edu
  6. Date: Mon, 22 Jan 1996 16:04:35 -0500 (EST)
  7. X-Mailer: ELM [version 2.4 PL23]
  8. Mime-Version: 1.0
  9. Content-Type: text/plain; charset=US-ASCII
  10. Content-Transfer-Encoding: 7bit
  11. Content-Length: 2786      
  12. Errors-To: icon-group-errors@cs.arizona.edu
  13. Status: O
  14.  
  15.  
  16. I'm not a member of the Icon Project; just an Icon enthusiast. I like
  17. the language a lot, but there's a handful of features I wish were there
  18. that aren't, in particular I wish it had closures. In the past, when
  19. I've brought this up, I was told that this wasn't going to be considered
  20. soon, besides which co-expressions provide a rough sort of closures.
  21.  
  22. So I've been looking lately to implement closures myself. After much
  23. consideration, the simplest way to do this, with the least amount of
  24. work needed is to modify the interpreter to load and save the values of
  25. closed local variables in a list a pointer to which is stored in the
  26. b_proc structure for each procedure; a new function (closeproc()) is
  27. used to create new copies of Icon procedure some, or all of whose local
  28. variables have persistent values. Those of you who are familiar with
  29. Lisp probably understand what I am talking about, for those who don't,
  30. the best way to describe this feature is that with it you can make
  31. copies of a procedure that has static variables such that each copy has
  32. _different_ static variables.
  33.  
  34. Here's how I'm going about implementing this:
  35.  
  36.     - add a new field to the b_proc structure: struct descrip closedvars
  37.       which should normally be &null or point to an Icon list.
  38.  
  39.     - fix invoke.r:invoke() so that when it's done manipulating the
  40.       stack it copies the stored values of closed variables into the
  41.       corresponding local variables on the stack. The list pointed
  42.       to by the new closedvars field of b_proc consists of
  43.       descriptor pairs, where the first descriptor is an integer
  44.       representing an index into the local variable array, and the
  45.       second descriptor is the stored value for that local
  46.       variable.
  47.  
  48.     - fix interp.r:interp() so that the values of closed local
  49.       variables are copied back into the closedvars list whenever a
  50.       procedure with closed variables returns or fails.
  51.  
  52.     - fix icont/lcode.c:lemitproc() and icont/lcode.c:gentables() so
  53.       the closedvars field of b_proc structures is initialized to
  54.       &null.
  55.  
  56.     - fix the firstd[] and other tables in rmemmgt.r.
  57.  
  58.     - fix init.r (the B_IProc(n) stuff).
  59.  
  60.     - add closeproc() to runtime/fmisc.r. This function should take
  61.       an Icon procedure as its first argument, followed by
  62.       variable_name:initial_value pairs. A more Lisp-like procedure
  63.       closing function can be built ontop of this.
  64.  
  65. I would much rather do the above for static procedure variables instead
  66. of local dynamic variables, but that would require much larger changes.
  67. I've got most of the above complete, and at least I have something that
  68. compiles (I have yet to test it). But since I'm have little knowledge of
  69. the implementation of Icon, I must ask wether there is any other place I
  70. must look in and edit to make this work.
  71.  
  72. Any comments? Ideas?
  73.  
  74. Nick
  75.